// components/footer/footer.js
let getWindowUrl = require('../../utils/util.js')
var app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    pageUrl: {
      type: String,
      value: '',
      observer: function () {

      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    learnClass: '',
    myClass: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    calClassActive () {
      let location = getWindowUrl.getWindowUrl()
      this.setData({
        location: location
      })
      if (location.indexOf('/home') > -1 || location.indexOf('/QAList') > -1 || location.indexOf('/done') > -1) {
        this.setData({
          learnClass: 'active',
          myClass: ''
        })
      }
      else if (location.indexOf('/usercenter') > -1 || location.indexOf('/errorReview') > -1 || location.indexOf('/errorReview') > -1 || location.indexOf('/studyPlan') > -1 || location.indexOf('/userInfo') > -1) {
        this.setData({
          learnClass: '',
          myClass: 'active'
        })
      } 
    },
    goto (e) {
      let authorization = wx.getStorageSync('authorization')
      let expiredtime = wx.getStorageSync('EXPIREDTIME')
      let openid = wx.getStorageSync('openId')
      if (authorization && expiredtime && openid) {
        app.globalData.historyUrlList = []
        app.globalData.currentURLkey = -1
        let params = e.currentTarget.dataset.url
        app.formDirectUrl('/pages/' + params)
      }
      else {
        wx.showModal({
          title: '提示',
          content: '您还未登录，请先登录',
          success: () => {
            // app.formDirectUrl('/pages/home/home')
          }
        })
      }
    }
  },
  attached () {
    this.calClassActive()
  }
})
